home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / hplip / plugin.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-10-28  |  12KB  |  273 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __version__ = '2.1'
  5. __mod__ = 'hp-plugin'
  6. __title__ = 'Plugin Download and Install Utility'
  7. __doc__ = ''
  8. import sys
  9. import getopt
  10. import time
  11. import os.path as os
  12. import re
  13. import os
  14. import gzip
  15. from base.g import *
  16. from base import device, utils, tui, module
  17. from prnt import cups
  18. pm = None
  19.  
  20. def plugin_download_callback(c, s, t):
  21.     pm.update(int(100 * c * s / t), utils.format_bytes(c * s))
  22.  
  23.  
  24. def plugin_install_callback(s):
  25.     print s
  26.  
  27. USAGE = [
  28.     (__doc__, '', 'name', True),
  29.     ('Usage: %s [MODE] [OPTIONS]' % __mod__, '', 'summary', True),
  30.     utils.USAGE_MODE,
  31.     utils.USAGE_GUI_MODE,
  32.     utils.USAGE_INTERACTIVE_MODE,
  33.     ('Installation for required printer mode:', '--required (Qt4 only)', 'option', False),
  34.     ('Installation for optional printer mode:', '--optional (Qt4 only)', 'option', False),
  35.     utils.USAGE_LANGUAGE,
  36.     utils.USAGE_OPTIONS,
  37.     ('Specify the path to the plugin file:', '-p <path> or --path=<path> or --plugin=<path>', 'option', False),
  38.     utils.USAGE_LOGGING1,
  39.     utils.USAGE_LOGGING2,
  40.     utils.USAGE_LOGGING3,
  41.     utils.USAGE_HELP,
  42.     utils.USAGE_SPACE,
  43.     utils.USAGE_SEEALSO,
  44.     ('hp-setup', '', 'seealso', False),
  45.     ('hp-firmware', '', 'seealso', False)]
  46. mod = module.Module(__mod__, __title__, __version__, __doc__, USAGE, (INTERACTIVE_MODE, GUI_MODE), (UI_TOOLKIT_QT3, UI_TOOLKIT_QT4), True)
  47. (opts, device_uri, printer_name, mode, ui_toolkit, loc) = mod.parseStdOpts('p:', [
  48.     'path=',
  49.     'plugin=',
  50.     'plug-in=',
  51.     'reason=',
  52.     'generic',
  53.     'optional',
  54.     'required'], handle_device_printer = False)
  55. plugin_path = None
  56. install_mode = PLUGIN_NONE
  57. plugin_reason = PLUGIN_REASON_NONE
  58. for o, a in opts:
  59.     None if o in ('-p', '--path', '--plugin', '--plug-in') else ui_toolkit == 'qt3'
  60.     if o == '--optional':
  61.         install_mode = PLUGIN_OPTIONAL
  62.         if ui_toolkit == 'qt3':
  63.             log.warn('--optional switch ignored.')
  64.         
  65.     ui_toolkit == 'qt3'
  66.     if o == '--reason':
  67.         plugin_reason = int(a)
  68.         continue
  69.  
  70. version = prop.installed_version
  71. plugin_filename = 'hplip-%s-plugin.run' % version
  72. if plugin_path is not None:
  73.     if not os.path.exists(plugin_path):
  74.         log.error("Plug-in path '%s' not found." % plugin_path)
  75.         sys.exit(1)
  76.     
  77.     if os.path.isdir(plugin_path):
  78.         plugin_path = os.path.join(plugin_path, 'hplip-%s-plugin.run' % version)
  79.         if not os.path.exists(plugin_path):
  80.             log.error("Plug-in path '%s' not found." % plugin_path)
  81.             sys.exit(1)
  82.         
  83.     
  84.     if os.path.basename(plugin_path) != plugin_filename:
  85.         log.error("Plug-in filename must be '%s'." % plugin_filename)
  86.         sys.exit(1)
  87.     
  88.     size = os.stat(plugin_path)[6]
  89.     checksum = ''
  90.     timestamp = 0
  91.     plugin_path = 'file://' + plugin_path
  92.     log.debug('Plugin path=%s (%d)' % (plugin_path, size))
  93.  
  94. if mode == GUI_MODE:
  95.     if ui_toolkit == 'qt3':
  96.         if not utils.canEnterGUIMode():
  97.             log.error('%s requires GUI support (try running with --qt4). Try using interactive (-i) mode.' % __mod__)
  98.             sys.exit(1)
  99.         
  100.     elif not utils.canEnterGUIMode4():
  101.         log.error('%s requires GUI support (try running with --qt3). Try using interactive (-i) mode.' % __mod__)
  102.         sys.exit(1)
  103.     
  104.  
  105. PKIT = utils.to_bool(sys_conf.get('configure', 'policy-kit'))
  106. if PKIT:
  107.     
  108.     try:
  109.         from base.pkit import *
  110.         
  111.         try:
  112.             pkit = PolicyKit()
  113.             pkit_installed = True
  114.         except dbus.DBusException:
  115.             ex = None
  116.             log.error('PolicyKit support requires DBUS or PolicyKit support files missing')
  117.             pkit_installed = False
  118.  
  119.     log.error('Unable to load pkit...is HPLIP installed?')
  120.     pkit_installed = False
  121.  
  122. else:
  123.     pkit_installed = False
  124. if mode == GUI_MODE:
  125.     pass
  126. None if ui_toolkit == 'qt3' else None<EXCEPTION MATCH>KeyboardInterrupt
  127.  
  128. try:
  129.     if not os.geteuid() == 0:
  130.         log.error('You must be root to run this utility.')
  131.         sys.exit(1)
  132.     
  133.     log.info("(Note: Defaults for each question are maked with a '*'. Press <enter> to accept the default.)")
  134.     log.info('')
  135.     from installer import core_install
  136.     core = core_install.CoreInstall()
  137.     core.set_plugin_version()
  138.     tui.header('PLUG-IN INSTALLATION FOR HPLIP %s' % version)
  139.     if core.check_for_plugin() and plugin_path is None:
  140.         log.info('The driver plugin for HPLIP %s appears to already be installed.' % version)
  141.         (cont, ans) = tui.enter_yes_no('Do you wish to download and re-install the plug-in?')
  142.         if not cont or not ans:
  143.             sys.exit(0)
  144.         
  145.     
  146.     if plugin_path is None:
  147.         table = tui.Formatter(header = ('Option', 'Description'), min_widths = (10, 50))
  148.         table.add(('d', 'Download plug-in from HP (recomended)'))
  149.         table.add(('p', 'Specify a path to the plug-in (advanced)'))
  150.         table.add(('q', 'Quit hp-plugin (skip installation)'))
  151.         table.output()
  152.         (cont, ans) = tui.enter_choice('\nEnter option (d=download*, p=specify path, q=quit) ? ', [
  153.             'd',
  154.             'p'], 'd')
  155.         if not cont:
  156.             sys.exit(0)
  157.         
  158.         if ans == 'd':
  159.             plugin_conf_url = core.get_plugin_conf_url()
  160.             if plugin_conf_url.startswith('file://'):
  161.                 tui.header('COPY CONFIGURATION')
  162.             else:
  163.                 tui.header('DOWNLOAD CONFIGURATION')
  164.                 log.info('Checking for network connection...')
  165.                 ok = core.check_network_connection()
  166.                 if not ok:
  167.                     log.error('Network connection not detected.')
  168.                     sys.exit(1)
  169.                 
  170.             log.info('Downloading configuration file from: %s' % plugin_conf_url)
  171.             pm = tui.ProgressMeter('Downloading configuration:')
  172.             (plugin_path, size, checksum, timestamp, ok) = core.get_plugin_info(plugin_conf_url, plugin_download_callback)
  173.             print 
  174.             if not plugin_path.startswith('http://') and not plugin_path.startswith('file://'):
  175.                 plugin_path = 'file://' + plugin_path
  176.             
  177.         else:
  178.             while True:
  179.                 plugin_path = raw_input(log.bold("Enter the path to the 'hplip-%s-plugin.run' file (q=quit) : " % version)).strip()
  180.                 if plugin_path.strip().lower() == 'q':
  181.                     sys.exit(1)
  182.                 
  183.                 if not plugin_path.startswith('http://'):
  184.                     plugin_path = os.path.normpath(os.path.abspath(os.path.expanduser(plugin_path)))
  185.                     if not os.path.exists(plugin_path):
  186.                         log.error("Plug-in path '%s' not found." % plugin_path)
  187.                         continue
  188.                     
  189.                     if os.path.isdir(plugin_path):
  190.                         plugin_path = os.path.join(plugin_path, plugin_filename)
  191.                         if not os.path.exists(plugin_path):
  192.                             log.error("Plug-in path '%s' not found." % plugin_path)
  193.                             continue
  194.                         
  195.                     
  196.                     if os.path.basename(plugin_path) != plugin_filename:
  197.                         log.error("Plug-in filename must be '%s'." % plugin_filename)
  198.                         continue
  199.                     
  200.                     size = os.stat(plugin_path)[6]
  201.                     checksum = ''
  202.                     timestamp = 0
  203.                     plugin_path = 'file://' + plugin_path
  204.                 
  205.                 break
  206.     
  207.     if plugin_path.startswith('file://'):
  208.         tui.header('COPY PLUGIN')
  209.     else:
  210.         tui.header('DOWNLOAD PLUGIN')
  211.         log.info('Checking for network connection...')
  212.         ok = core.check_network_connection()
  213.         if not ok:
  214.             log.error('Network connection not detected.')
  215.             sys.exit(1)
  216.         
  217.     log.info('Downloading plug-in from: %s' % plugin_path)
  218.     pm = tui.ProgressMeter('Downloading plug-in:')
  219.     (status, ret) = core.download_plugin(plugin_path, size, checksum, timestamp, plugin_download_callback)
  220.     print 
  221.     if status in (core_install.PLUGIN_INSTALL_ERROR_UNABLE_TO_RECV_KEYS, core_install.PLUGIN_INSTALL_ERROR_DIGITAL_SIG_NOT_FOUND):
  222.         log.error('Digital signature file download failed. Without this file, it is not possible to authenticate and validate the plug-in prior to installation.')
  223.         (cont, ans) = tui.enter_yes_no('Do you still want to install the plug-in?', 'n')
  224.         if not cont or not ans:
  225.             sys.exit(0)
  226.         
  227.     elif status != core_install.PLUGIN_INSTALL_ERROR_NONE:
  228.         if status == core_install.PLUGIN_INSTALL_ERROR_PLUGIN_FILE_NOT_FOUND:
  229.             desc = 'Plug-in file not found (server returned 404 or similar error). Error code: %s' % str(ret)
  230.         elif status == core_install.PLUGIN_INSTALL_ERROR_DIGITAL_SIG_BAD:
  231.             desc = 'Plug-in file does not match its digital signature. File may have been corrupted or altered. Error code: %s' % str(ret)
  232.         elif status == core_install.PLUGIN_INSTALL_ERROR_PLUGIN_FILE_CHECKSUM_ERROR:
  233.             desc = 'Plug-in file does not match its checksum. File may have been corrupted or altered.'
  234.         elif status == core_install.PLUGIN_INSTALL_ERROR_NO_NETWORK:
  235.             desc = 'Unable to connect to network to download the plug-in. Please check your network connection and try again.'
  236.         elif status == core_install.PLUGIN_INSTALL_ERROR_DIRECTORY_ERROR:
  237.             desc = 'Unable to create the plug-in directory. Please check your permissions and try again.'
  238.         
  239.         core.delete_plugin()
  240.         log.error(desc)
  241.         sys.exit(1)
  242.     
  243.     tui.header('INSTALLING PLUG-IN')
  244.     core.run_plugin(mode, plugin_install_callback)
  245.     cups_devices = device.getSupportedCUPSDevices([
  246.         'hp'])
  247.     title = False
  248.     for dev in cups_devices:
  249.         mq = device.queryModelByURI(dev)
  250.         if mq.get('fw-download', 0):
  251.             if not title:
  252.                 tui.header('DOWNLOADING FIRMWARE')
  253.                 title = True
  254.             
  255.             log.info(log.bold('\nDownloading firmware to device %s...' % dev))
  256.             
  257.             try:
  258.                 d = device.Device(dev)
  259.             except Error:
  260.                 log.error('Error opening device. Exiting.')
  261.                 sys.exit(1)
  262.  
  263.             if d.downloadFirmware():
  264.                 log.info('Firmware download successful.\n')
  265.             
  266.             d.close()
  267.             continue
  268. except KeyboardInterrupt:
  269.     log.error('User exit')
  270.  
  271. log.info('')
  272. log.info('Done.')
  273.